package cn.tedu.core_banking.controller;

import cn.tedu.core_banking.base.response.JsonResult;
import cn.tedu.core_banking.base.response.StatusCode;
import cn.tedu.core_banking.mapper.CustomerMapper;
import cn.tedu.core_banking.pojo.dto.AddCustomer;
import cn.tedu.core_banking.pojo.entity.Customer;
import cn.tedu.core_banking.service.CustoemrService;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;

import org.apache.coyote.Request;
import org.springdoc.core.service.GenericResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("api/customer/")
@Slf4j
@Tag(name = "客户管理模块", description = "客户管理相关操作")
public class CustomerController {
    @Autowired
    private CustoemrService custoemrService;
    @Autowired
    private GenericResponseService responseBuilder;

    @Operation(summary = "注册新用户")
    @PostMapping("add")
    public JsonResult insertCustomer(@RequestBody AddCustomer addCustomer, HttpSession session ){
        List<Customer> customer = custoemrService.insertCustomer(addCustomer);
        session.setAttribute("customer",customer);
        return new JsonResult(StatusCode.SUCCESS,customer);

    }
    @Operation(summary = "获取用户列表")
    @GetMapping("list")
    public JsonResult getCustomerList( HttpServletResponse response
    ) throws IOException {
        log.debug("获取用户列表");
        //进行用户校验
//        HttpSession session1 = session.getAttribute("customer");
//        if (session == null){
//            response.sendRedirect("login.html");
//        }
        List<Customer> customerList =  custoemrService.customerList();
        return new JsonResult(StatusCode.SUCCESS,customerList);

    }


}
